/*
 * =====================================================================================
 *
 *       Filename:  wektor.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  19.01.2010 17:15:48
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Michal Antonczak (uzyszkodnik), uzyszkodnik.priv@gmail.com
 *        Company:  
 *
 * =====================================================================================
 */

#include 	"wektor.h"
#include	<cmath>

using namespace std;
Wektor::Wektor(){

return;

}
Wektor::Wektor(double val, double iangle){

        x=val*sin(iangle);
        y=val*cos(iangle);
        angle=iangle;
}

void Wektor::setval(double val, double iangle){

        x=val*sin(iangle);
        y=val*cos(iangle);
	value=val;
        angle=iangle;
}

Wektor operator+ (const Wektor& a,const Wektor&b){

	Wektor tmp;
	tmp.x=a.x+b.x;
	tmp.y=a.y+b.y;
	tmp.angle=atan2(tmp.x,tmp.y);
	tmp.value=sqrt(tmp.x*tmp.x+tmp.y*tmp.y);
	return tmp;
}

Wektor operator- (const Wektor& a,const Wektor&b){

	Wektor tmp;
	tmp.x=a.x-b.x;
	tmp.y=a.y-b.y;
	tmp.angle=atan2(tmp.x,tmp.y);
	tmp.value=sqrt(tmp.x*tmp.x+tmp.y*tmp.y);
	return tmp;
}

Wektor operator*(const Wektor&a, const double&b){

	Wektor tmp;
	tmp.value = a.value*b;
	//#define DEBUG(DEBUGME, NAME)  printf("%s, x:%f, y:%f, value:%f, angle:%f\n",NAME,DEBUGME.x, DEBUGME.y, DEBUGME.value, DEBUGME.angle)
	tmp.angle=a.angle;
	//DEBUG(a,"przed:");	
	tmp.x=tmp.value*sin(tmp.angle);
        tmp.y=tmp.value*cos(tmp.angle);
	//DEBUG(tmp,"po");
	return tmp;
}

Wektor operator/ (const Wektor&a, const double&b){

	Wektor tmp;
	tmp.angle=a.angle;
	tmp.value = a.value/b;
	tmp.x=tmp.value*sin(tmp.angle);
        tmp.y=tmp.value*cos(tmp.angle);

	return tmp;
}


